/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controladores;

import ejb.negocio.PropuestaServiceLocal;
import entidades.Paises;
import entidades.Planeseco;
import entidades.Planesecotrad;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;

/**
 *
 * @author Pablo
 */

public class ParentController {
    

    private ResourceBundle bundle;
    private static List<SelectItem> plEcoSelect;
    private static List<SelectItem> paisSelect;
    protected String idioma = "ES"; ///////////////   Obtenerlo correctamente.
   
    @EJB
    protected PropuestaServiceLocal propuestaService;
    /**
     * Creates a new instance of ParentController
     */
    public ParentController() {
        FacesContext facesContext = FacesContext.getCurrentInstance();                
        bundle = facesContext.getApplication().getResourceBundle(facesContext, "msg");         
    }

    
    protected void createMessageError(String place, String keyMessage){
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, 
                    bundle.getString(keyMessage), bundle.getString(keyMessage));
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(place, message);                     
    }

    public ResourceBundle getBundle() {
        return bundle;
    }

    public void setBundle(ResourceBundle bundle) {
        this.bundle = bundle;
    }
    
     //public List cargaListas(List<SelectItem> paisSelect, List<SelectItem> plEcoSelect){
    public void cargaListaPaises(){
        paisSelect = new ArrayList<>();
        ArrayList<Paises> paises = propuestaService.getListaPaises();
        for (int i=0; i<paises.size(); i++){
            Paises pais = paises.get(i);
            //int idPais = paises.get(i).getIdPais();
            paisSelect.add(new SelectItem(pais.getIdPais(), 
                    propuestaService.getPaisTrad(pais, idioma).getNombre()));
        }
    }
     
    public void cargaListaPlEco()  {
        plEcoSelect = new ArrayList<>();
        ArrayList <Planeseco> planesEco = propuestaService.getListaPlanesEco();
        for (int i=0; i<planesEco.size(); i++){
            //int idPlan = planesEco.get(i).getIdPlan();
            Planeseco plan = planesEco.get(i);
            Planesecotrad pet = propuestaService.getPlanEcoTrad(plan, idioma);
            plEcoSelect.add(new SelectItem(plan.getIdPlan(), pet.getNombre(), 
                    pet.getDescripcion()));
            /***********
            //planesEco.get(i).getNombre(), planesEco.get(i).getDescripcion()));
            * *********/
        }
    }
    
    public List<SelectItem> getPaisSelect() {
        return paisSelect;
    }

    public void setPaisSelect(List<SelectItem> newPaisSelect) {
        paisSelect = newPaisSelect;
    }

    public List<SelectItem> getPlEcoSelect() {
        return plEcoSelect;
    }

    public void setPlEcoSelect(List<SelectItem> newPlEcoSelect) {
        plEcoSelect = newPlEcoSelect;
    }
}
